Skip to main content

The __v Property

The __v property of a Model instance is a special internal value which indicates the "version" of the data that the Model was instantiated from during database read operations. It is generated by calculating a hash of the record after it was read from disk. The __v property exists on all Model instances and is accessible to consumers of the Model.

How Its Used

The __v property is primarily used during save operations in order to ensure that the current state of the data has not changed since the Model was instantiated. In order to ensure data integrity, MVOM will reject saves where the contents of a record has changed between the time a Model instance was created and the time the record is written to disk. If MVOM detects that a record has changed it will abort the save attempt and throw a DocumentVersionMismatchError.

Related: Saving a Model